package cn.myjerry.composite;

import java.util.ArrayList;
import java.util.List;

public interface AbstractFile {
	void killVirus();
}

class ImageFile implements AbstractFile {
	private String Name;
	
	public ImageFile(String name) {
		super();
		Name = name;
	}

	@Override
	public void killVirus() {
		System.out.println("====图像文件：" + Name + "，开始查杀");
	}
	
}

class TxtFile implements AbstractFile {
	private String Name;
	
	public TxtFile(String name) {
		super();
		Name = name;
	}

	@Override
	public void killVirus() {
		System.out.println("====文本文件：" + Name + "，开始查杀");
	}
	
}

class VideoFile implements AbstractFile {
	private String Name;
	
	public VideoFile(String name) {
		super();
		Name = name;
	}

	@Override
	public void killVirus() {
		System.out.println("====视频文件：" + Name + "，开始查杀");
	}
	
}

class Folder implements AbstractFile {
	private String Name;
	private List<AbstractFile> list = new ArrayList<>();
	
	public Folder(String name) {
		super();
		Name = name;
	}

	public void add(AbstractFile file) {
		list.add(file);
	}
	
	public void remove(AbstractFile file) {
		list.remove(file);
	}
	
	public AbstractFile getchild(int index) {
		return list.get(index);
	}
	
	@Override
	public void killVirus() {
		System.out.println("====文件夹：" + Name + "，开始查杀");
		
		for(AbstractFile file : list) {
			file.killVirus();
		}
	}
	
}
